//
//  MBHomePPVCell.m
//  Meboo
//
//  Created by kyo on 2024/4/28.
//

#import "MBHomePPVCell.h"

@interface MBHomePPVCell()
@property(nonatomic,strong) UILabel *moneyLab;
@property(nonatomic,strong) UILabel *titleLab;
@property (nonatomic, strong) UIImageView *arrowImageView;
@property (nonatomic, strong) CAGradientLayer *gradient;
@end

@implementation MBHomePPVCell
- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

#pragma mark - Public Metohd
- (void)setDict:(NSMutableDictionary *)dict {
    self.titleLab.text = [NSString stringWithFormat:@"%@",dict[@"title"]];
    self.moneyLab.text = [NSString stringWithFormat:@"%@",dict[@"money"]];
    
    [self.gradient removeFromSuperlayer];
    if ([[NSString stringWithFormat:@"%@",dict[@"isSelected"]] integerValue] == 1) {
        [self.contentView.layer insertSublayer:self.gradient atIndex:0];
    } else {

    }
}

#pragma mark - Action
//- (void)deleteCloth {
//    if (self.deleteBlock) {
//        self.deleteBlock();
//    }
//}

#pragma mark - UI
- (void)setupUI {
    self.contentView.backgroundColor = [UIColor colorWithRed:255 / 255.0 green:255 / 255.0 blue:255 / 255.0 alpha:0.7];
    self.contentView.layer.cornerRadius = MBHeightScale(10);
    self.contentView.layer.masksToBounds = YES;
    
    [self.contentView addSubview:self.moneyLab];
    [self.moneyLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(MBWidthScale(23));
        make.bottom.equalTo(self.contentView.mas_centerY).offset(MBHeightScale(-3));
    }];
    
    [self.contentView addSubview:self.titleLab];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(MBWidthScale(23));
        make.top.equalTo(self.contentView.mas_centerY).offset(MBHeightScale(3));
    }];
    
    [self.contentView addSubview:self.arrowImageView];
    [self.arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.right.mas_equalTo(MBWidthScale(-14));
    }];
    
}

#pragma mark - Setter && Getter


- (UILabel *)moneyLab {
    if (!_moneyLab) {
        _moneyLab = [UILabel new];
        _moneyLab.font = MBHelBoldFontSizeScale(16);
        _moneyLab.textColor = HEXS(@"000000");
    }
    return _moneyLab;
}

- (UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [UILabel new];
        _titleLab.font = MBHelBoldFontSizeScale(16);
        _titleLab.textColor = HEXS(@"000000");
    }
    return _titleLab;
}

- (UIImageView *)arrowImageView {
    if (!_arrowImageView) {
        _arrowImageView = [UIImageView new];
        _arrowImageView.image = ImageWithName(@"home_pop_pppv_arrow");
    }
    return _arrowImageView;
}

- (CAGradientLayer *)gradient {
    if (!_gradient) {
        //渐变色 设置开始和结束位置(设置渐变的方向)
       _gradient = [CAGradientLayer layer];
        _gradient.startPoint = CGPointMake(0, 0);
        _gradient.endPoint = CGPointMake(1, 1);
        _gradient.locations = @[@(0.0),@(0.46),@(1.0f)];
        _gradient.frame = self.contentView.bounds;
        _gradient.colors = [NSArray arrayWithObjects:(id)HEXS(@"FFD748").CGColor,(id)HEXS(@"FFC940").CGColor,(id)HEXS(@"FFC940").CGColor,nil];
    }
    return _gradient;
}
@end
